package util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DataHelper {
	
	public static String dateToStringDB(Date data){
		SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");		
		return dt.format(data).toString();			
	}
	
	public static String dateDBToString(Date d){
		
		SimpleDateFormat dt = new SimpleDateFormat("dd-MM-yyyy");		
		String a = dt.format(d);
		String[] p = a.split("-");		
		String data = "";
		data = p[0]+"/";
		data += p[1]+"/";
		data += p[2];
		return data;
					
	}
	
	public static Date stringToDate(String data){
		
		String[] aux = data.split("/");
		
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(aux[0]));
		cal.set(Calendar.MONTH, (Integer.parseInt(aux[1])-1));
		cal.set(Calendar.YEAR, Integer.parseInt(aux[2]));		
		
		return cal.getTime();		
	}
}
